package com.app.support.utils;

import com.ctc.wstx.sw.EncodingXmlWriter;
import org.apache.commons.codec.binary.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Lichaojie on 2017/3/11. It's a beautiful day.
 */
public class SHAUtil {
    public static String sha(String password) {
        MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        byte[] ret = messageDigest.digest(password.getBytes());
        return Base64.encodeBase64String(ret);
    }

    public static String sha256(String password){
        MessageDigest messageDigest = null;
        try{
            messageDigest = MessageDigest.getInstance("SHA-256");
        }catch (Exception ex){

        }

        return Base64.encodeBase64String(messageDigest.digest(password.getBytes()));
    }

    public static void main(String[] args){
        System.out.println(sha256("kristy"));
        System.out.println(sha256("lichaojie123"));
        System.out.println(sha("kristy"));
    }
}
